import time

import requests
import execjs

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
    'Cookie': 'sessionid=yvdjycdhjqu11dp98a8j327puakgf6tj;'
}
cookies = {
    'sessionid': 'z19b3sxqjoulcjrpfb0o6f8wlylaaj30;',
    'm': '',
    'RM4hZBv0dDon443M': ''
}
params = {
    # 'page': '',
    'm': '',
    'f': ''
}
url = 'https://match.yuanrenxue.cn/api/match/5?page=%s'
js_code = open('jscode.js', 'r', encoding='utf-8').read()
res_lst = []
for i in range(1, 6):
    js_compile = execjs.compile(js_code)
    js_result = js_compile.call('run')
    params['m'] = str(js_result['m'])
    params['f'] = js_result['f']
    headers['Cookie'] = headers['Cookie'] + 'm=' + js_result['cookie_m'] + ';' + 'RM4hZBv0dDon443M=' + js_result[
        'cookie_RM4']+';'
    response = requests.get(url % i, headers=headers, params=params)
    json_data = response.json()
    res_lst.extend([i.get('value') for i in json_data.get('data')])
res_lst.sort(reverse=True)
print(res_lst)
print('前五名热度之和为:'+str(sum(res_lst[:5])))